package com.shujia.mr.tuijian;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class PersonReducer extends Reducer<Text, LongWritable, Text, Text> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, Text>.Context context) throws IOException, InterruptedException {
        //只要一个组合中的迭代器里面有1的存在，那么这个组合就属于直接好友
        boolean flag = true;
        for (LongWritable value : values) {
            if(value.get()==1){
                flag = false;
                break;
            }
        }

        if(flag){
            context.write(key,new Text("间接好友"));
        }else {
            context.write(key,new Text("直接好友"));
        }
    }
}
